package com.example.crm.servlet;

import com.example.crm.dao.ConnectDAO;
import com.example.crm.domain.Connect;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet("/editconnect")
public class EditConnectServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();


        // 1. 获取参数
        String idStr = req.getParameter("id");
        int id = Integer.parseInt(idStr);


        // 2. 调用model
        ConnectDAO dao = new ConnectDAO();
        Connect c = null;
        try {
            c = dao.findById(id);

            req.setAttribute("connect", c);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        // 3. 请求转发
        req.getRequestDispatcher("jsp/connect/edit.jsp").forward(req, resp);


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}